Add matomo integration #931
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Title
Add Matomo analytics integration for GitBook (pageviews, referrers, clicks, goals, SPA)
Overview
Adds a new analytics integration enabling published GitBook sites to send analytics to a Matomo cloud or self‑hosted instance. Consent-aware and SPA-friendly.
integrations/matomo
site
Implementation
integrations/matomo/gitbook-manifest.yaml
site:script:inject
,site:script:cookies
analytics
script-src
,img-src
,connect-src
to user-provided Matomo hosts (host is configured per site)server_url
(required): Matomo base URLsite_id
(required): Matomo site IDload_js_tracker
(default true): loadmatomo.js
for richer tracking; beacon fallback when disabledtrack_referrer
(default true)track_outbound_clicks
(default true)click_selectors
(string): comma-separated CSS selectors for custom click eventsgoal_mappings_json
(string): JSON mapping of CSS selectors → Matomo Goal IDsuser_id_cookie
(string): cookie name to set Matomouid
integrations/matomo/src/index.ts
: serves configured tracking scriptintegrations/matomo/src/matomoScript.raw.js
:matomo.js
load (first‑party cookies, enableLinkTracking)uid
from cookieglobal.d.ts
,package.json
,tsconfig.json
,CHANGELOG.md
,assets/icon.png
Security and privacy
matomo.js
when enabled; otherwise a lightweight Tracking API beacon to the configured hostTesting
npm i -g @gitbook/cli
gitbook auth --token <token>
integrations/matomo
:gitbook dev <spaceId>
server_url
,site_id
(+ optional fields)<server_url>/matomo.php
and, if enabled,<server_url>/matomo.js
References